﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
	<META http-equiv="content-type" content="text/html; charset=windows-1250">
	<META name="generator" content="PSPad editor, www.pspad.com">
	<TITLE>turn page</TITLE>
	<script type="text/javascript" language="javascript" src="../js/jq/1.8/jquery-1.8.3.min.js"></script>
	<script type="text/javascript" language="javascript" src="../js/turn.min.js"></script>	
	<script type="text/javascript" language="javascript" >
		$(document).ready(function() { 
			$('#magazine').turn();
		});
		function formatNum(strNum) {
			if (strNum.length <= 3) {
				return strNum;
			}
			if (!/^(\+|-)?(\d+)(\.\d+)?$/.test(strNum)) {
				return strNum;
			}
			var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
			var re = new RegExp();
				re.compile("(\\d)(\\d{3})(,|$)");
			while (re.test(b)) {
				b = b.replace(re, "$1,$2$3");
			}
			return a + "" + b + "" + c;
		}
		
		alert(formatNum(1231111111121.12));
	</script>
	<style type="text/css">    
		#magazine{
			width:800px;
			height:600px;
		}
		#magazine .turn-page{
			width:400px;
			height:600px;
			background-color:#006699;
		}
	</style>
</head>    
   
<body style="text-align:center">
	<div id='magazine'>
		<div> Page 1 <br/>
			例如： <br/>
			12345格式化为12,345.00 <br/>
			12345.6格式化为12,345.60 <br/>
			12345.67格式化为 12,345.67 <br/>
			只留两位小数。 <br/>

			回来后写了个格式化函数。可以控制小数位数，自动四舍五入。<br/>
			
			function fmoney(s, n) {   <br/>
			   n = n > 0 && n <= 20 ? n : 2;   <br/>
			   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   <br/>
			   var l = s.split(".")[0].split("").reverse(),   <br/>
			   r = s.split(".")[1];   <br/>
			   t = "";   <br/>
			   for(i = 0; i < l.length; i ++ )   <br/>
			   {   <br/>
				  t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   <br/>
			   }   <br/>
			   return t.split("").reverse().join("") + "." + r;  <br/> 
			} <br/>

			调用：fmoney("12345.675910", 3)，返回12,345.676 		<br/>
		
		</div>
		<div> Page 2 
			function formatNum(strNum) {<br/>
				if (strNum.length <= 3) {<br/>
					return strNum;<br/>
				}<br/>
				if (!/^(\+|-)?(\d+)(\.\d+)?$/.test(strNum)) {<br/>
					return strNum;<br/>
				}<br/>
				var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;<br/>
				var re = new RegExp();<br/>
					re.compile("(\\d)(\\d{3})(,|$)");<br/>
				while (re.test(b)) {<br/>
					b = b.replace(re, "$1,$2$3");<br/>
				}<br/>
				return a + "" + b + "" + c;<br/>
			}<br/>
			
			調用：formatNum(123456789.12)， 返回 123,456,789.12<br/>
		</div>
		<div> Page 3  兵1</div>
		<div> Page 4  兵2</div>
	</div>
</body>    
</html> 
